/*
 * @Author: Ethan
 * @Github: https://github.com/ethanpub
 * @Date: 2019-05-22 17:29:06
 * @LastEditors: Ethan
 * @Blog: https://ethan.pub
 * @LastEditTime: 2019-12-04 14:25:59
 * @Description: 🙏BUG退散🙏
 */
import Vue from 'vue'
import Router from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Login from '@/components/Login'
import { GlobalStore } from '@/store/global'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    scrollBehavior: (...arg) => arg[2] || { x: 0, y: 0 },
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            redirect: '/login',
            meta: {
                name: '主页'
            }
        },
        {
            path: '/login',
            component: Login,
            meta: {
                name: '登录'
            }
        },
        {
            path: '/403',
            component: () => import('@/views/exception/403')
        },
        {
            path: '/404',
            component: () => import('@/views/exception/404')
        },
        {
            path: '/500',
            component: () => import('@/views/exception/500')
        },
        {
            path: '*',
            redirect: '/404'
        }
    ]
})

router.beforeEach((to, form, next) => {
    NProgress.start()
    GlobalStore.getUserInfo()
    next()
})
router.afterEach(() => NProgress.done())

export default router
